package com.zdb.util;

// 建议dashscope SDK的版本 >= 2.12.
import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.aliyun.bailian20231229.Client;
import com.aliyun.bailian20231229.models.ApplyFileUploadLeaseResponse;
import com.aliyun.teaopenapi.models.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class Main {
    private static final Logger log = LoggerFactory.getLogger(Main.class);
    public static Client createCong() throws Exception {

       Config config = new Config()
                .setAccessKeyId("LTAI5tA9G1cQUMTDVaupwwPh")
                .setAccessKeySecret("5UxepwbaRBeufPcO5KBa7gikiiFJII");
        config.setEndpoint("bailian.cn-beijing.aliyuncs.com");
        return new Client( config);
    }
    public static void main(String[] args) throws Exception {
        ApplyFileUploadLeaseResponse applyFileUploadLeaseResponse = applyFileUploadLeaseResponse(createCong(), "default", "test.txt", "5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c", "1024", "default");
        log.info(String.valueOf(applyFileUploadLeaseResponse.getBody()));
    }
    public static  ApplyFileUploadLeaseResponse applyFileUploadLeaseResponse(Client client, String categoryId, String fileName, String fileMd5, String fileSize, String workspaceId) throws Exception {
        Map<String, String> headers = new HashMap<>();
        com.aliyun.bailian20231229.models.ApplyFileUploadLeaseRequest applyFileUploadLeaseRequest = new com.aliyun.bailian20231229.models.ApplyFileUploadLeaseRequest();
        applyFileUploadLeaseRequest.setFileName(fileName);
        applyFileUploadLeaseRequest.setMd5(fileMd5);
        applyFileUploadLeaseRequest.setSizeInBytes(fileSize);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        ApplyFileUploadLeaseResponse applyFileUploadLeaseResponse = null;
        applyFileUploadLeaseResponse = client.applyFileUploadLeaseWithOptions(categoryId, workspaceId, applyFileUploadLeaseRequest, headers, runtime);
        return applyFileUploadLeaseResponse;
    }
}